<?php 
/**
 * 定时清除临时文件
 */

include 'init.php';
$expires = 86400; // 过期时间
$dir = _DIRECTORY_VAR . DIRECTORY_SEPARATOR . 'tmp';

_clear($dir);


function _clean($filename) {
	global $expires;
	$time = @filemtime($filename);
	if($time + $expires < time()) {
		@unlink($filename);
		echo date('Y-m-d H:i:s', $time) . "\t\t$filename\r\n";
	}
}

function _clear($dir) {
	if(!is_dir($dir)) {
		return ;
	}
	$handle = opendir($dir);
	while(false !== ($name = readdir($handle))) {
		if($name != "." && $name != "..") {
			$filename = $dir . DIRECTORY_SEPARATOR . $name;
			if((is_dir($filename))) {
				_clear($filename);
			} else {
				_clean($filename);
			}
		}
	}
	closedir($handle);
}
